﻿@model RoadFlow.Model.Program
<form id="form1" method="post">
    @Html.AntiForgeryToken()
    <input type="hidden" name="Id" value="@Model.Id" />
    <input type="hidden" name="CreateTime" value="@Model.CreateTime.ToString()" />
    <input type="hidden" name="CreateUserId" value="@Model.CreateUserId" />
    <table cellpadding="0" cellspacing="1" border="0" width="99%" class="formtable" style="margin-top:10px;">
        <tr>
            <th style="width: 80px;">应用名称：</th>
            <td><input type="text" id="Name" name="Name" value="@Model.Name" class="mytext" validate="empty" style="width: 85%" /></td>
        </tr>
        <tr>
            <th style="width: 80px;">应用分类：</th>
            <td>
                <select class="myselect" name="Type" errmsg="应用分类不能为空" validate="empty">
                    <option value=""></option>
                    @Html.Raw(ViewData["appTypeOptions"])
                </select>
                &nbsp;&nbsp;数据连接：<select class="myselect" name="ConnId" id="ConnId">
                    @Html.Raw(ViewData["dbconnOptions"])
                </select>
                &nbsp;&nbsp;按钮显示位置：<select class="myselect" name="ButtonLocation" id="ButtonLocation">
                    <option value="0" @(Model.ButtonLocation == 0 ? "selected ='selected' " : "")>新行</option>
                    <option value="1" @(Model.ButtonLocation == 1 ? "selected ='selected' " : "")>查询后面</option>
                </select>
                &nbsp;&nbsp;是否分页：<select class="myselect" name="IsPager">
                    <option value="1" @(Model.IsPager == 1 ? "selected ='selected' " : "")>是</option>
                    <option value="0" @(Model.IsPager == 0 ? "selected ='selected' " : "")>否</option>
                </select>
                &nbsp;&nbsp;选择列：<select class="myselect" name="SelectColumn">
                    <option value="0" @(Model.SelectColumn == 0 ? "selected ='selected' " : "")>无</option>
                    <option value="1" @(Model.SelectColumn == 1 ? "selected ='selected' " : "")>单选</option>
                    <option value="2" @(Model.SelectColumn == 2 ? "selected ='selected' " : "")>多选</option>
                </select>
                &nbsp;&nbsp;序号列：<select class="myselect" name="RowNumber">
                    <option value="0" @(Model.RowNumber == 0 ? "selected ='selected' " : "")>不显示</option>
                    <option value="1" @(Model.RowNumber == 1 ? "selected ='selected' " : "")>显示</option>
                </select>
            </td>
        </tr>
        <tr>
            <th>表单：</th>
            <td>
                <select class="myselect" style="width:130px; max-height:200px;" onchange="form_types_change(this.value);" id="form_types">
                    <option value=""></option>
                    @Html.Raw(ViewData["formTypeOptions"])
                </select>
                <select class="myselect" id="FormId" name="FormId"></select>
                &nbsp;&nbsp;编辑方式：<select id="EditModel" onchange="form_editmodel_change(this.value)" class="myselect" name="EditModel">
                    <option value="0" @(Model.EditModel == 0 ? "selected ='selected' " : "")>当前窗口</option>
                    <option value="1" @(Model.EditModel == 1 ? "selected ='selected' " : "")>弹出层</option>
                    <option value="2" @(Model.EditModel == 2 ? "selected ='selected' " : "")>弹出窗口</option>
                </select>
                <span id="form_editmodel_span">
                    &nbsp;&nbsp;弹出宽度：<input type="text" class="mytext" id="Width" name="Width" value="@Model.Width" style="width:60px" />
                    高度：<input type="text" id="Height" name="Height" value="@Model.Height" class="mytext" style="width:60px" />
                </span>
            </td>
        </tr>
        <tr>
            <th style="width: 80px;">查询SQL：</th>
            <td><textarea style="width:99%; height:200px; font-family:Verdana; font-size:14px;" id="SqlString" name="SqlString" validate="empty" class="mytextarea">@Model.SqlString</textarea></td>
        </tr>
        <tr>
            <th style="width: 80px;">表头合并：</th>
            <td><textarea style="width:99%; height:100px; font-family:Verdana; font-size:14px;" id="GroupHeaders" name="GroupHeaders" class="mytextarea">@Model.GroupHeaders</textarea></td>
        </tr>
        <tr>
            <th style="width: 80px;">页面脚本：</th>
            <td><textarea style="width:99%; height:100px; font-family:Verdana; font-size:14px;" id="ClientScript" name="ClientScript" class="mytextarea">@Model.ClientScript</textarea></td>
        </tr>
        <tr style="display: none">
            <th style="width: 80px;">列表表头：</th>
            <td><textarea style="width:99%; height:80px; font-family:Verdana; font-size:14px;" id="TableHead" name="TableHead" class="mytextarea">@Model.TableHead</textarea></td>
        </tr>
        <tr>
            <th style="width: 80px;">导出：</th>
            <td>
                <span style="display: none">模板：<input type="text" id="ExportTemplate" name="ExportTemplate" value="@Model.ExportTemplate" class="myfile" /></span>
                &nbsp;&nbsp;表头：<input type="text" class="mytext" value="@Model.ExportHeaderText" id="ExportHeaderText" name="ExportHeaderText" style="width:400px" />
                &nbsp;&nbsp;文件名：<input type="text" class="mytext" value="@Model.ExportFileName" id="ExportFileName" name="ExportFileName" style="width:200px" />
            </td>
        </tr>
    </table>
    <input type="hidden" name="InDataNumberFiledName" value="@Model.InDataNumberFiledName" />
    <div class="buttondiv">
        <input type="button" value=" 保 存 " onclick="save(this);" class="mybutton" />
    </div>
</form>
<script type="text/javascript">
    $(function () {
        form_types_change($("#form_types").val());
        form_editmodel_change($("#EditModel").val());
        //loadTables($("#dbconnId").val(), '', '');
    });
    function form_types_change(value) {
        $.ajax({
            url: "../Applibrary/GetOptionsByAppType@(Html.Raw(ViewData["queryString"]))", data: { type: value, "value": "@Model.FormId" }, async: false, type: "post", success: function (txt) {
                $("#FormId").html('<option value=""></option>' + txt);
            }
        });
    }
    function form_editmodel_change(value) {
        if ("1" === value || "2" === value) {
            $("#form_editmodel_span").show();
        }
        else {
            $("#form_editmodel_span").hide();
        }
    }
    function loadTables(connid, tableName, filedName) {
        var tables = "<option></option>";
        $.ajax({
            url: "../Dbconnection/GetTableOptions?connid=" + connid,
            dataType: "json",
            async: false,
            cache: false,
            success: function (json) {
                for (var i = 0; i < json.length; i++) {
                    tables += '<option value="' + json[i].name + '"' + (json[i].name.toLowerCase() == tableName.toLowerCase() ? ' selected="selected"' : '') + '>' + json[i].name + '</option>';
                }
                $("#DBTable").html(tables);
                if (tableName && tableName.length > 0) {
                    getFields(connid, tableName, filedName);
                }
            }
        });
    }
    //得到一个表所有字段
    function getFields(connid, tableName, filedName) {
        var fields1 = '<option></option>';
        $.ajax({
            url: "../Dbconnection/GetFieldsOptions?connid=" + connid + "&table=" + tableName,
            dataType: "json",
            async: false,
            cache: false,
            success: function (json) {
                for (var i = 0; i < json.length; i++) {
                    fields1 += '<option value="' + json[i].name + '"' + (json[i].name.toLowerCase() == filedName.toLowerCase() ? ' selected="selected"' : '') + '>' + json[i].name + '</option>';
                }
                $("#DBFiled").html(fields1);
            }
        });
    }

    function save(but) {
        var f = document.forms[0];
        if (new RoadUI.Validate().validateForm(f)) {
            var o = RoadUI.Core.serializeForm($(f));
            $(but).prop("disabled", true);
            $.ajax({
                url: "SaveAttr@(Html.Raw(ViewData["queryString"]))", data: o, type: "post", success: function (text) {
                    alert(text);
                    $(but).prop("disabled", false);
                    parent.location = "Edit?programid=@(Model.Id)&@(Html.Raw(ViewData["query"]))";
                }
            });
        }
    }
</script>
